<?php
/**
 * admin_group_operations模型
 * @author 
 * @version 1.0
 * @package application
 * @subpackage application/models
 */

class Admin_group_operations_Model extends MY_Model
{
 
	public function __construct(){
		parent::__construct();
		$this->_pk='';
		$this->_attributes=array( 
				'group_id'=>'',
				'operations_id'=>'',
				'created'=>'',
				'modified'=>'',
				'status'=>'',
		);
	}

	public $_table = array(
       		 'ago' => 'admin_group_operations',
	);
	
	/**
	 * 添加管理员组权限
	 * @param int $group_id 权限组ID
	 * @param array $operations 权限de数组
	 */
	public function add_opera($group_id,$operations){
		foreach($operations as $operation){
			$attributes=array();
			$attributes=array(
				'group_id'=>$group_id,
				'operations_id'=>$operation,
			);
			$this->insert($attributes);
		}
	}

	/**
	 * 修改管理员组权限
	 * @param int $group_id 权限组ID
	 * @param array $add_operations 要添加权限的数组
	 * @param array $del_operations 要修改的权限的数组
	 * @by dengle
	 */
	public function edit_opera($group_id, $add_operations , $del_operations){
		if($add_operations){
			$this->add_opera($group_id, $add_operations);
		}
		if($del_operations){
			$this->delete_opera($group_id, $del_operations);
		}
	}

	/**
	 * 删除权限组权限
	 * @param int $group_id 权限组ID
	 * @param array $operations 权限de数组
	 */
	public function delete_opera($group_id,$operations){
		foreach($operations as $operation){
			$attributes=array();
			$attributes=array(
				'group_id'=>$group_id,
				'operations_id'=>$operation,
			);
			$this->delete_by_attributes($attributes);
		}
	}


}